package com.example.bzh.gamecat.httputils;

import com.example.bzh.gamecat.config.HttpUrl;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by ${kissfoot} on 2016/8/4.
 */
public class RetrofitHelper {
    private static RetrofitHelper ourInstance;

    public static synchronized RetrofitHelper getInstance() {
        if (ourInstance == null){
            ourInstance = new RetrofitHelper();
        }
        return ourInstance;
    }

    private RetrofitHelper() {
    }

    public Retrofit retrofit;
    public Gson gson;

    public <T>T  createRetrofitService(Class<T> service){
        if (retrofit == null){
            createGson();
            initRetrofit();
        }
        return retrofit.create(service);
    }

    private void initRetrofit() {
        retrofit = new Retrofit.Builder()
                .baseUrl(HttpUrl.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();

    }

    private void createGson() {
        gson = new GsonBuilder()
                .serializeNulls()
                .create();
    }


}













